function HiddenCollection(container, defaultName){
	this.container=container;
	this.defaultName=defaultName;
	
	this.getCount=function () {
		return this.container.childNodes.length;
	}
	
	this.getHiddenByIndex=function (index) {
		if (index==undefined||index==null) return null;
		if (index>=this.container.childNodes.length){
			return null;
		}
		return this.container.childNodes[index];
	}
	
	this.getHiddenByName=function (name) {
		for (var i=0; i<this.container.childNodes.length; i++){
			if (this.container.childNodes[i].name==name){
				return this.container.childNodes[i];
			}
		}
		return null;
	}

	this.getValueByIndex=function (key) {
		var hidden=this.getHiddenByIndex(key);
		if (hidden) {
			return hidden.value;
		}
		return null;
		
	}	

	this.getValueByName=function (key) {
		var hidden=this.getHiddenByName(key);
		if (hidden) {
			return hidden.value;
		}
		return null;
		
	}	

	this.setValueByIndex=function (index, value, closeGaps) {
		if (closeGaps==undefined) {
			closeGaps=true;
		}
		
		if (this.getCount()<=index&&closeGaps){
			for (var i=this.getCount(); i<=index ;i++){
				this.add("");
			}
		}
		
		var hidden=this.getHiddenByIndex(index);
		if (!hidden) return;
		
		hidden.value=value;					
	}		
	
	this.add=function (value, name) {
		this.insert(this.createHidden(name, value), null);
	}
	
	this.insert=function (hidden, index) {
		if (index==undefined){
			index=null;
		}	
		var prevNode=this.getHiddenByIndex(index);
		this.container.insertBefore(hidden, prevNode);
	}
					
	this.createHidden=function (name, value) {
		if (!name){
			name=this.defaultName;
		}
		
		var hidden=document.createElement("input");
		hidden.type="hidden";
		hidden.name=name;
		hidden.value=value;
		
		return hidden;
	}
	
	this.clear=function () {
		while (this.container.hasChildNodes()){
			this.container.removeChild(this.container.childNodes[0]);	
		}
	}

		
}

